package com.common.basic.tags;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;

import com.common.basic.base.BaseTaglib;

public class CalendarTaglib extends BaseTaglib {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6957799938008665524L;
	private String field;
	private String altKey;
	private String monthYearOnly;

	/*
	 * <IMG src="images/en/cal.gif" onclick="displayDatePicker('validDate');"
	 * onmouseover="javascript:document.body.style.cursor = 'hand';"
	 * onmouseout="javascript:document.body.style.cursor = 'default';"
	 * alt="Date" />
	 */
	public static final String FIRST_SECTION = "<img src=\"";
	public static final String SECOND_SECTION = "\" onclick=\"displayDatePicker('";
	public static final String SECOND_AND_HALF_SECTION = "','','my";
	public static final String THIRD_SECTION = "');\" onmouseover=\"javascript:document.body.style.cursor = 'hand';\" onmouseout=\"javascript:document.body.style.cursor = 'default';\"  alt=\"";
	public static final String FORTH_SECTION = "\" />";

	/*
	 * Overide super class method
	 */
	public int doStartTag() throws JspException {
		super.doStartTag();
		HttpSession session = pageContext.getSession();
		String theme = (String)session.getAttribute(com.common.basic.util.Globals.THEME_PATH);
		write(
				pageContext,
				new StringBuffer(FIRST_SECTION)
//						.append(getRequestContext().getContextPath())
//						.append('/')
						.append(theme +
								getMessage(
										"image.calendar",
										null,
										getRequestContext().getLocale()))
						.append(SECOND_SECTION)
						.append(field)
						.append(
								"true".equalsIgnoreCase(monthYearOnly) ? SECOND_AND_HALF_SECTION
										: "")
						.append(THIRD_SECTION)
						.append(
								altKey == null ? "Date"
										: getMessage(
												altKey,
												null,
												getRequestContext().getLocale()))
						.append(FORTH_SECTION).toString());
		return SKIP_BODY;
	}

	/*
	 * Get alt key to get from resource to display tooltip message for the image
	 * 
	 * @return alt key to get from resource to display tooltip message for the
	 * image
	 */
	public String getAltKey() {
		return altKey;
	}

	/*
	 * Set alt key to get from resource to display tooltip message for the image
	 * 
	 * @param altKey alt key to get from resource to display tooltip message for
	 * the image
	 */
	public void setAltKey(String altKey) {
		this.altKey = altKey;
	}

	/*
	 * Get field in the form
	 * 
	 * @return field in the form
	 */
	public String getField() {
		return field;
	}

	/*
	 * Set field in the form
	 * 
	 * @param field field in the form
	 */
	public void setField(String field) {
		this.field = field;
	}

	/*
	 * Get month year only
	 * 
	 * @return month year only
	 */
	public String getMonthYearOnly() {
		return monthYearOnly;
	}

	/*
	 * Set month year only
	 * 
	 * @param monthYearOnly month year only
	 */
	public void setMonthYearOnly(String monthYearOnly) {
		this.monthYearOnly = monthYearOnly;
	}
}